package ModelLayer;
/**
 * DelSalg container a Vare object.
 * This delsalg object can return a vare and
 * its price of one Vare object if you
 * only are buying one Vare.
 * */
public class DelSalg {
	private int antal;
	private Vare vare;
	private int vareAN;
	
	/**
	 * Instance to VareContainer*/
	private VareContainer vCon;
	/**
	 * Creates a DelSalg object containing a 
	 * Vare object and a amount of the object.
	 * Find the Vare object by its artikelNr
	 * @param int antal, int artikelNr*/
	public DelSalg(int a, int aN)
	{
		vCon =  VareContainer.getInstance();
		this.antal = a;
		Vare v = vCon.findVare(aN);
		if(v != null){
			int ant = v.getAntal() - this.antal;
			v.setAntal(ant);
			this.vare = vCon.findVare(aN);
		}
	}
	
	/**
	 * Returns the Vare object declared in the constructor.
	 * @return Vare object*/
	public Vare getVare()
	{
		return vare;
	}
	/**
	 * Set the vare object of this object.
	 * Finds the vare in vareContainer by its artikelNr
	 * and sets it equal to vare.
	 * @param Int ArtikelNr*/
	public void setVare(int aN)
	{
		vare = vCon.findVare(aN);
	}
	/**
	 * Set amount of Vare's to buy.
	 * @param Int antal
	 * */
	public void setAntal(int a)
	{
		this.antal = a;
	}
	/**
	 * Returns the antal of the Vare object you are buying
	 * @return int antal*/
	public int getAntal()
	{
		return this.antal;
	}
	/**
	 * Returns the total price of all the vares as a float.
	 * @return float totalPrice
	 * */
	public float getTotalPrice()
	{
		return vare.getPris() * antal;
	}
	/**
	 * Returns the price of one of the vare objects
	 * @return float vare price
	 * */
	public float getPriceOfOne()
	{
		return vare.getPris();
	}
	/**
	 * Returns the artikelNr of the vare object to
	 * make it easier for the Salg object to remove a delSalg
	 * object from it.
	 * @param int artikelNr
	 * @return vare if artikelNr == vare.artikelNr else return null
	 * */
	public Vare getVareAN(int aN)
	{
		if(aN == vare.getArtikelNr())
		{
			return vare;
		}else{
			return null;
		}
	}
	
}
